package com.ruoyi.web.controller.numericalselection;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.numericalselection.domain.GmAttribute;
import com.ruoyi.numericalselection.service.IGmAttributeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 属性Controller
 *
 * @author ruoyi
 * @date 2024-06-02
 */
@RestController
@RequestMapping("/system/attribute")
public class GmAttributeController extends BaseController {
    @Autowired
    private IGmAttributeService gmAttributeService;

    /**
     * 查询属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(GmAttribute gmAttribute) {
        startPage();
        List<GmAttribute> list = gmAttributeService.selectGmAttributeList(gmAttribute);
        return getDataTable(list);
    }

    /**
     * 导出属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:export')")
    @Log(title = "属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GmAttribute gmAttribute) {
        List<GmAttribute> list = gmAttributeService.selectGmAttributeList(gmAttribute);
        ExcelUtil<GmAttribute> util = new ExcelUtil<GmAttribute>(GmAttribute.class);
        util.exportExcel(response, list, "属性数据");
    }

    /**
     * 获取属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(gmAttributeService.selectGmAttributeById(id));
    }

    /**
     * 新增属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:add')")
    @Log(title = "属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GmAttribute gmAttribute) {
        return toAjax(gmAttributeService.insertGmAttribute(gmAttribute));
    }

    /**
     * 修改属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:edit')")
    @Log(title = "属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GmAttribute gmAttribute) {
        return toAjax(gmAttributeService.updateGmAttribute(gmAttribute));
    }

    /**
     * 删除属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:remove')")
    @Log(title = "属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gmAttributeService.deleteGmAttributeByIds(ids));
    }


    /**
     * 查询属性
     */
    @GetMapping("/getAttribute/{id}")
    public AjaxResult getAttribute(@PathVariable("id") Long id) {
        return success(gmAttributeService.getAttribute(id));
    }

    /**
     * 区服
     */


}
